package queue;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws Exception {
        CircleQueue<Integer> arrayQueue = new CircleQueue(5);
        //接收用户输入
        char key = ' ';
        //输入流
        Scanner scanner = new Scanner(System.in);
        //控制程序结束的标记
        boolean loop = true;
        //程序运行，提供一个循环操作给用户
        while (loop){
            System.out.println("s(show): 显示队列");
            System.out.println("e(exit): 退出程序");
            System.out.println("a(add): 添加数据到队列");
            System.out.println("p(pop): 从队列取出数据");
            System.out.println("h(head): 查看队列头的数据");
            key = scanner.next().charAt(0);//获取用户输入的第一个字符
            switch (key){
                case 's':
                    arrayQueue.displayQueue();
                    break;
                case 'a':
                    System.out.println("输入一个数");
                    int value = scanner.nextInt();
                    arrayQueue.add(value);
                    break;
                case 'p':
                    try {
                        int i = arrayQueue.pop();
                        System.out.printf("取出的数据是%d\n",i);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'h':
                    try {
                        int i = arrayQueue.getHead();
                        System.out.printf("队列的头数据为%d\n",i);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'e':
                    loop = false;
                    break;
                default:
                    System.out.println("输入非法，请重新输入");
                    break;
            }
        }
        System.out.println("程序退出~~");
    }
    }

